package com.me;

import com.github.tobato.fastdfs.FdfsClientConfig;
import org.apache.catalina.Context;
import org.apache.tomcat.util.scan.StandardJarScanner;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
@ServletComponentScan
@EnableTransactionManagement
@Import(FdfsClientConfig.class)
@ComponentScan({"com.me.modules.activiti.org.activiti", "com.me"})
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
public class App extends SpringBootServletInitializer {

    private final String EXPOSE_HEADER = "DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Token";

    public static void main(String[] args) {
        System.setProperty("es.set.netty.runtime.available.processors", "false");

        ConfigurableApplicationContext configurableApplicationContext = SpringApplication.run(App.class, args);
        Environment environment = configurableApplicationContext.getBean(Environment.class);
        System.out.println("\n\n ============> 系统启动成功！后台地址：http://localhost:" + environment.getProperty("server.port"));
    }

    @Bean
    public TomcatServletWebServerFactory tomcatFactory() {
        return new TomcatServletWebServerFactory() {
            @Override
            protected void postProcessContext(Context context) {
                ((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
            }
        };
    }

}
